<?php
/*
Plugin Name: RandomTalk - Widgetized
Plugin URI:  http://cinefilo.homelinux.net/blog/plugin-wordpress/randomtalk-widget/
Description: Widget version of plugin <a href="http://mangasverdes.es/?page_id=1226">RandomTalk</a> and <strong>it is required to have activated it</strong>.
Author: Luis P&eacute;rez (cinefilo)
Version: 1.3
Author URI: http://cinefilo.homelinux.net/blog


  Copyright (c) 2006 by Luis Perez (cinefilo) (email : cinefilo@gmail.com) 
  
  http://www.gnu.org/copyleft/gpl.html

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

Credits

This widget use RandomTalk plugin version released by Manuel Almeida [http://mangasverdes.es/?page_id=1226].

Changelog:

	- v1.3 (09-19-2006): Add support localization. Include .mo file.
	- v1.2 (01-09-2006): Fix bug in the activation.
	- v1.1 (06-08-2006): Add credits.
	- v1.0 (05-08-2006): Initial released.

 */

/* Localization */

load_plugin_textdomain('randomtalk_widget','wp-content/plugins/widgets/');


function widget_randomtalk_init() {

	if ( !function_exists('register_sidebar_widget') )
		return;


	function widget_randomtalk($args) {
		

		extract($args);
		$options = get_option('widget_randomtalk');
		$title = $options['title'];
		$limit = $options['limit'];
		$comments = $options['comments'];			


		echo $before_widget . $before_title . $title . $after_title;
		switch($comments){
			case 1 :  if (function_exists('random_talk'))
					random_talk($limit); 
			          break;
			case 2 :  if (function_exists('get_random_talk'))
					get_random_talk($limit); 
			          break;
			case 3 :  if (function_exists('all_random_talk'))
					all_random_talk($limit); 
				  break;
			default : break;					
		}				
		
		echo $after_widget;

	}

	function widget_randomtalk_control() {

		$options = get_option('widget_randomtalk');
		
		if ( !is_array($options) )
			$options = array( 'title' => 'RandomTalk', 'limit' => 5,'comments'=> 1);

		if ( $_POST['randomtalk-submit'] ) {

			$options['title'] = strip_tags(stripslashes($_POST['randomtalk-title']));
			$options['limit'] = strip_tags(stripslashes($_POST['randomtalk-limit']));		 	 
			$options['comments'] = strip_tags(stripslashes($_POST['randomtalk-comments']));			
			update_option( 'widget_randomtalk', $options );			
		}

		$title = htmlspecialchars($options['title'], ENT_QUOTES);
		$limit = htmlspecialchars($options['limit'], ENT_QUOTES);
		$comments = htmlspecialchars($options['comments'], ENT_QUOTES);


	?>
	
	<p><?php _e('Title:','randomtalk_widget'); ?> <input style="width: 250px;" id="randomtalk-title" name="randomtalk-title" type="text" value="<?php echo $title; ?>" /></p>
		<p style="text-align:right;margin-right:40px;"><?php _e('Limits:','randomtalk_widget'); ?>  <input type="text" id="randomtalk-limit" name="randomtalk-limit" value="<?php echo $limit ?>" size="3" maxlength="3"/></p>						
		<p style="text-align:right;margin-right:40px;"><?php _e('Only authors with URL:','randomtalk_widget'); ?> <input type="radio" id="randomtalk-comments" name="randomtalk-comments" value="1" <?php if ($comments == 1) echo'checked'; ?> /></p>	
		<p style="text-align:right;margin-right:40px;"><?php _e('All authors:','randomtalk_widget'); ?> <input type="radio" id="randomtalk-comments" name="randomtalk-comments" value="2"  <?php if ($comments == 2) echo 'checked';  ?>/></p>	
		<p style="text-align:right;margin-right:40px;"><?php _e('All authors (Pingback/Trackback):','randomtalk_widget'); ?><input type="radio" id="randomtalk-comments" name="randomtalk-comments" value="3"  <?php if ($comments == 3) echo 'checked';  ?> /></p>

	<input type="hidden" id="randomtalk-submit" name="randomtalk-submit" value="1" />
<?php		
	}
	

	register_sidebar_widget('RandomTalk', 'widget_randomtalk');
	register_widget_control('RandomTalk', 'widget_randomtalk_control', 380, 200);
}

add_action('plugins_loaded', 'widget_randomtalk_init');

?>
